home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
tchrt3.zip
/
WATCH.C
< prev
next >
Wrap
Text File
|
1990-07-18
|
18KB
|
437 lines
/*---------------------------------------------------------------------------
| Program WATCH |
| |
| This program creates a stopwatch on the display with "Taylor" split |
| capability. |
| |
| This program uses two timers to keep track of total and lap times. |
| This method can result in a least significant digit "jitter" of .01 sec |
| on the lap timer. A better, but more complex method is to use a single |
| timer to keep track of both. The dual timer method makes for better |
| demo code and was chosen for that reason only. |
| |
| NOTE: Compile with stack checking disabled. |
| |
| (c)1989 Ryle Design, P.O. Box 22, Mt. Pleasant, Michigan 48804 |
| |
| V3.00 Turbo C Shareware Evaluation Series | |
---------------------------------------------------------------------------*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include "pchrt.h"
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define TIMEROFF 0
#define TIMERON 1
#define LAPSTOP 0
#define LAPRUN 1
#define F1 59
#define F2 60
#define KEYPORT 0x60
#define MSMINS 60000000L;
#define MSSECS 1000000L;
#define MSHUNDS 10000L;
char tstring[9] = {"00:00.00"};
char lstring[9] = {"00:00.00"};
int tstate = TIMEROFF;
int lstate = LAPSTOP;
int laps;
unsigned long ltime = 0;
unsigned long ttime = 0;
pchrt_type dtime[2];
void interrupt (*old_keybd_int)(void); /* pointer to old keyboard interrupt */
void interrupt new_keybd_int(void); /* our new keyboard interrupt */
int hide_cursor(void)
/*--------------------------------------------------------------------------
| This function disables the cursor. |
| |
| Globals referenced: none |
| |
| Arguments : void |
| |
| Returns : (int) cursor shape for later restoration |
--------------------------------------------------------------------------*/
{
union REGS regs;
int cursortype;
regs.h.ah = 15; /* get current video page */
int86(0x10,®s,®s);
regs.h.ah = 3; /* request cursor shape */
int86(0x10,®s,®s); /* regs.bh has video page from last int86() call */
cursortype = regs.h.cl + ( (int) regs.h.ch << 8); /* store cursor start & stop rasters */
regs.h.ah = 1; /* set cursor shape */
regs.h.ch = 32; /* set bit 5 - turns cursor off */
int86(0x10,®s,®s); /* and disable cursor */
return(cursortype);
} /* hide_cursor */
void set_cursor(int cursortype)
/*---------------------------------------------------------------------------
| This function sets the cursor to a new shape. |
| |
| Globals referenced: none |
| |
| Arguments : (int) cursortype - high 8 bits is start raster |
| low 8 bits is stop raster |
| Returns : void |
---------------------------------------------------------------------------*/
{
union REGS regs;
regs.h.ah = 1; /* set cursor shape */
regs.h.ch = (cursortype & 0xFF00) >> 8; /* cursor start raster */
regs.h.cl = (cursortype & 0x00FF); /* cursor stop raster */
int86(0x10,®s,®s); /* call BIOS interupt 10h */
} /* set_cursor */
void restore_old_keybd_int(void)
/*---------------------------------------------------------------------------
| This function restores the original keyboard interrupt and must be |
| called prior to program completion. |
| |
| Globals referenced: old_keybd_int |
| |
| Arguments: void |
| |
| Returns : void |
---------------------------------------------------------------------------*/
{
setvect(9,old_keybd_int); /* restore old ISR vector */
} /* restore_old_keybd_int */
void install_new_keybd_int(void)
/*---------------------------------------------------------------------------
| This function saves the original keyboard interrupt vector and installs |
| the address of our user written interrupt handler in the ISR vector |
| table. |
| |
| Globals referenced: old_keybd_int |
| new_keybd_int |
| |
| Arguments: void |
| |
| Returns : void |
---------------------------------------------------------------------------*/
{
old_keybd_int = getvect(9); /* save old ISR vector */
setvect(9,new_keybd_int); /* install new ISR vector */
} /* install_new_keybd_int */
void interrupt far new_keybd_int(void)
/*---------------------------------------------------------------------------
| This function is our new interrupt service routine for interrupt 9h. |
| The following occurs: |
| 1. The keyboard hardware port is read to see what key was pressed. |
| 2. If F1 or F2 were pressed, the watch state is checked and |
| appropriate action is taken. |
| 3. The old keyboard interrupt is called. |
| |
| Since this function is invoked by a hardware interrupt, it functions |
| asynchronously to the main program execution and provides extremely |
| high timing accuracy. |
| |
| Globals referenced: tstate